home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / mflzt.exe / lha / INPATH.C < prev    next >
Text File  |  1989-10-30  |  3KB  |  118 lines

  1. /*
  2. **                INPATH UTILITY
  3. ** This is a program similar to many "filefind" programs, except that
  4. ** it works like the UNIX "whereis" command.  The command line argument
  5. ** (only one, please) is taken to be the name of an executable
  6. ** program, and is searched under extensions .BAT, .COM, and .EXE
  7. ** for the first occurance of the program.  The search starts
  8. ** in the current directory, and if not found, procedes using the
  9. ** PATH environment variable (if there is one).  The program reports the
  10. ** first occurance of the specified file, just as it would be found
  11. ** by DOS if executed.
  12. **
  13. ** The input filename need not contain an extension, since the
  14. ** extension is discarded anyway.
  15. **
  16. ** Version 1.05  for Turbo-C 2.0
  17. ** 11-08-88 A
  18. **
  19. **  Copyright 1988-89 by Steven E. Margison
  20. **
  21. **
  22. **   As distributed, this program requires (for compilation):
  23. **     "Steve's Turbo-C Library" version 1.41 or later
  24. **   which may be obtained without registration from many Bulletin
  25. **   Board Systems including:
  26. **      Compuserve IBMSW
  27. **      GEnie
  28. **   and software library houses including:
  29. **      Public (Software) Library (Houston, TX.)
  30. **
  31. **   or by registration:
  32. **      $25 for Docs, C, S, M, L, H libraries, and complete library source
  33. **              in C and Assembler
  34. **     Steven E. Margison
  35. **     124 Sixth Street
  36. **     Downers Grove, IL, 60515
  37. **
  38. */
  39.  
  40. #include <stdio.h>
  41. #include <mflsys.h>
  42.  
  43. char paths[256],
  44.      fullname[100],
  45.      dirname[100],
  46.      batname[14],
  47.      comname[14],
  48.      exename[14],
  49.      fname[14];
  50. int current;
  51.  
  52. main(argc, argv)
  53. int argc;
  54. char *argv[];
  55. {
  56.    int i, j, k;
  57.    char c;
  58.    if(argc != 2) usage();
  59.    strcpy(fname, argv[1]);   /* copy argument to fname */
  60.    newext(fname, batname, "BAT");   /* make fname.bat */
  61.    newext(fname, comname, "COM");   /* make fname.com */
  62.    newext(fname, exename, "EXE");   /* make fname.exe */
  63.    dirname[0] = NULL;
  64.    current = TRUE;
  65.    findpgm();
  66.    current = FALSE;
  67.    if((j = getpath(paths)) == 0) notfound();
  68.    k = 0;
  69.    while(j > 0) {
  70.       i = 0;
  71.       while(paths[k] != NULL) {
  72.       c = paths[k];      /* save for slash check */
  73.          dirname[i++] = paths[k++];
  74.          --j;
  75.          }
  76.       if (c != '\\') dirname[i++] = '\\';
  77.       dirname[i] = NULL;
  78.       ++k;      /* position to next charcter in paths[] */
  79.       --j;
  80.       findpgm();
  81.       }
  82.    notfound();
  83.    }
  84.  
  85. findpgm() {
  86.    strcpy(fullname, dirname);   /* test for .com file */
  87.    strcat(fullname, comname);
  88.    if(exists(fullname)) goto found;
  89.  
  90.    strcpy(fullname, dirname);
  91.    strcat(fullname, exename);   /* test for .exe file */
  92.    if(exists(fullname)) goto found;
  93.  
  94.    strcpy(fullname, dirname);
  95.    strcat(fullname, batname);   /* test for .bat file */
  96.    if(exists(fullname)) goto found;
  97.  
  98.    return(FALSE);         /* file not found */
  99.  
  100.    found:
  101.    if(current) puts("File found in current directory");
  102.    fputs(fullname, stdout);
  103.    fputc('\n', stdout);
  104.    exit(0);
  105.    return(FALSE);     /* to eliminate a compiler warning */
  106.    }
  107.  
  108. notfound() {
  109.    error("File not found in PATH");
  110.    }
  111.  
  112. usage() {
  113.    fputs("INPATH Version 1.10\n", stderr);
  114.    fputs("Copyright 1988-89, Steven E. Margison\n", stderr);
  115.    error("usage:  inpath <filename>");
  116.    }
  117.  
  118.